﻿using System;
using System.Collections.Generic;

using Kiiro.Common.Interfaces;

namespace Kiiro.Common.Entities
{
    [Serializable]
    public class TeamMember : BaseEntity, IEntity
    {
        #region Private Properties 

        private User user;
        //private User kiiroUser;
        private int userId;
        private List<ValidationMessage> userIdMessage = new List<ValidationMessage>();
        private string roleOnProject;
        private List<ValidationMessage> roleOnProjectMessage = new List<ValidationMessage>();
        private bool isProjectManager;
        private List<ValidationMessage> isProjectManagerMessage = new List<ValidationMessage> ( );
        
        #endregion

        #region Public Properties

        public new int UserId                   // use new keyword to override/hide IPermissions.UserId property as it is not necessary on this entity object
        {
            get { return userId; }
            set
            {
                if (userId != value)
                {
                    userId = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> UserIdMessage
        {
            get { return userIdMessage; }
            set
            {
                if (userIdMessage != value)
                {
                    userIdMessage = value;
                    UpdateEntity();
                }
            }
        }

        public bool IsProjectManager
        {
            get { return this.isProjectManager; }
            set
            {
                if (this.isProjectManager != value)
                {
                    this.isProjectManager = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> IsProjectManagerMessage
        {
            get { return isProjectManagerMessage; }
            set
            {
                if (isProjectManagerMessage != value)
                {
                    isProjectManagerMessage = value;
                    UpdateEntity();
                }
            }
        }

        public string RoleOnProject
        {
            get { return roleOnProject; }
            set
            {
                if (roleOnProject != value)
                {
                    roleOnProject = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> RoleOnProjectMessage
        {
            get { return roleOnProjectMessage; }
            set
            {
                if (roleOnProjectMessage != value)
                {
                    roleOnProjectMessage = value;
                    UpdateEntity();
                }
            }
        }

        public User User
        {
            get { return user; }
            set
            {
                if ( user != value )
                {
                    user = value;
                    //UpdateEntity ( );
                }
            }
        }

        //public User KiiroUser
        //{
        //    get { return kiiroUser; }
        //    set
        //    {
        //        if (user != value)
        //        {
        //            kiiroUser = value;
        //            UpdateEntity ( );
        //        }
        //    }
        //}

        #endregion

        #region IEntity Members

        public new bool IsValid()
        {
            return AllValidationErrors().Count == 0;
        }

        public new List<ValidationMessage> AllValidationErrors()
        {
            List<ValidationMessage> allErrors = new List<ValidationMessage>();

            allErrors.AddRange(userIdMessage);
            allErrors.AddRange(isProjectManagerMessage);
            allErrors.AddRange(roleOnProjectMessage);
            allErrors.AddRange(EditTypeMessage);

            return allErrors;
        }

        public new void ClearValidationMessages()
        {
            userIdMessage.Clear();
            isProjectManagerMessage.Clear();
            roleOnProjectMessage.Clear();
            EditTypeMessage.Clear();
        }

        #endregion
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Common/Entities/TeamMember.cs $
 * 
 * 6     17/08/09 10:38a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/